package vip.xiaonuo.smzq.modular.kcl.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import vip.xiaonuo.smzq.modular.kcl.entity.Yf;
import vip.xiaonuo.smzq.modular.kcl.mapper.YfMapper;
import vip.xiaonuo.smzq.modular.kcl.service.IYfService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import vip.xiaonuo.common.page.CommonPageRequest;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 压覆 服务实现类
 *
 * @author eomer
 * @since 2024-02-22
 */
@Service
public class YfServiceImpl extends ServiceImpl<YfMapper, Yf> implements IYfService {

    @Resource
    private YfMapper yfMapper;

    @Override
    public Page<Yf> page(Yf yf) {
        QueryWrapper<Yf> queryWrapper = new QueryWrapper<>();
        return this.page(CommonPageRequest.defaultPage(), queryWrapper);
    }

    @Override
    public List<Yf> getYfList(String kqbm, Integer djflbm, Integer nd) {
        List<Yf> yfList = new ArrayList<>();

        try {
            QueryWrapper<Yf> queryWrapper = new QueryWrapper<>();
            queryWrapper.eq("kqbh", kqbm);
            queryWrapper.eq("djflbh", djflbm);
            queryWrapper.eq("nd", nd);
            yfList=yfMapper.selectList(queryWrapper);
        }catch (Exception e){
            e.printStackTrace();
        }

        return yfList;
    }

    @Override
    public int addList(List<Yf> yfList,String kqbm, Integer djflbm, Integer nd) {
        int count = 0;
        for (Yf yf : yfList) {
            yf.setKqbh(kqbm);
            yf.setDjflbh(djflbm);
            yf.setNd(nd);
            if (yf.getPkid() != null&&yf.getPkid().length()>0){
                count = yfMapper.updateById(yf);
            }else{
                count = yfMapper.insert(yf);
            }
        }
        return count;
    }

    @Override
    public List<Yf> selectList(QueryWrapper<Yf> queryWrapperYf) {
        return yfMapper.selectList(queryWrapperYf);
    }
}
